package com.study.s11.flyweight;

public class MainClass {
	
	public static void main(String[] args) {
		
		//===================旧模式===================
//		MyCharacter myChar1 = new MyCharacter('a');
//		MyCharacter myChar2 = new MyCharacter('b');
//		MyCharacter myChar3 = new MyCharacter('c');
//		MyCharacter myChar4 = new MyCharacter('d');
//		MyCharacter myChar5 = new MyCharacter('a');
		//===========================================
		
		//===================新模式===================
		//1、新建MyCharacter工厂
		MyCharacterFactory myCharacterFactory = new MyCharacterFactory();
		//2、从MyCharacter工厂取出MyCharacter对象
		MyCharacter myChar1 = myCharacterFactory.getMyCharacter('a');
		MyCharacter myChar2 = myCharacterFactory.getMyCharacter('b');
		MyCharacter myChar3 = myCharacterFactory.getMyCharacter('c');
		MyCharacter myChar4 = myCharacterFactory.getMyCharacter('d');
		MyCharacter myChar5 = myCharacterFactory.getMyCharacter('a');
		
		//===========================================
		
		myChar1.display();
		myChar2.display();
		myChar3.display();
		myChar4.display();
		myChar5.display();
		
		//判断对象是否相同
		if(myChar1 == myChar5) {
			System.out.println("对象相同");
		} else {
			System.out.println("对象不相同");
		}
	}
}
